<%@ page import="pers.lt.tools.StringFacs" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    request.setAttribute("basePath",basePath);
%>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
    <jsp:include page="../../common/jsp/jqueryResource.jsp"></jsp:include>
    <link rel="stylesheet" href="${basePath}bootstrap/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="${basePath}bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${basePath}bootstrap/css/font-awesome.min.css" >
    <link rel="stylesheet" href="${basePath}bootstrap/bootstrap-datepicker/bootstrap.css">
    <link rel="stylesheet" href="${basePath}bootstrap/css/custom.min.css" >
    <link rel="stylesheet" href="${basePath}bootstrap/css/templatemo-style.css" >
    <link rel="stylesheet" href="${basePath}bootstrap/css/bootstrapValidator.css" >
    <link rel="stylesheet" href="${basePath}bootstrap/bootstrap-datepicker/bootstrap-datetimepicker.min.css" >
    <script src="${basePath}bootstrap/js/bootstrap-table.min.js"></script>
    <script src="${basePath}bootstrap/js/bootstrap-datetimepicker.js"></script>
    <script src="${basePath}bootstrap/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="${basePath}bootstrap/js/bootstrap.min.js"></script>
    <script src="${basePath}javascript/import/importlist.js"></script>
    <%--<script src="${basePath}javascript/query/query.js"></script>--%>
    <script type="text/javascript" src="${basePath}bootstrap/bootstrap-datepicker/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>

</head>
<style>
    input,button{
        display:inline-block!important;
    }
</style>
<body>
<div class="templatemo-flex-row" style="height: 100%;">
    <!-- Main content -->
    <div class="templatemo-content col-1 light-gray-bg">
        <div class="templatemo-content-container">
            <div class="container" style="padding-bottom:0px;">
                <div class="panel panel-default">
                    <div class="panel-heading">导入查询</div>
                    <div class="panel-body">
                        <form id="formSearch" class="form-horizontal">
                            <div class="row">
                                <div class="col-sm-">
                                    <form enctype="multipart/form-data" id="drbatchUpload"  action="drimportlist.html" method="post" class="form-horizontal">
                                        <button class="btn btn-success btn-xs" id="druploadEventBtn" style="height:26px;"  type="button" >选择文件</button>
                                        <input type="file" name="drfile"  style="width:0px;height:0px;" id="druploadEventFile">
                                        <input id="druploadEventPath"  disabled="disabled"  type="text" placeholder="请择excel表" style="border: 1px solid #e6e6e6; height: 26px;width: 200px;" />
                                    </form>
                                    <button type="button" class="btn btn-success btn-sm" style="width: 72px" onclick="user.druploadBtn()" >上传</button>
                                    <button type="button" class="btn btn-success btn-sm" id="dc"  style="width: 72px">导出</button>
                                    <button type="button" class="btn btn-success btn-sm" id="back"  onclick="javascript:history.back(-1);" style="width: 72px;margin-left: 800px">返回主页</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <table id="query_data"></table>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    var user;
    $(function() {
        user = new User();
        user.init();
    })
    //导入查询
    /* $('drcx').bind('click',function () {*/
    var User = function() {
        this.init = function() {
            //模拟上传excel
            $("#druploadEventBtn").unbind("click").bind("click", function() {
                $("#druploadEventFile").click();
            });
            $("#druploadEventFile").bind("change", function() {
                $("#druploadEventPath").attr("value",    $("#druploadEventFile").val());
            });
        };
        //点击上传钮
        this.druploadBtn = function() {
            var uploadEventFile = $("#druploadEventFile").val();
            if (uploadEventFile == '') {
                alert("请择excel,再上传");
            } else if (uploadEventFile.lastIndexOf(".xls") < 0) {//可判断以.xls和.xlsx结尾的excel
                alert("只能上传Excel文件");
            } else {
                var url = "drimportlist.html";
                debugger;
                var formData = new FormData($('form')[0]);
                user.sendAjaxRequest(url, "POST", formData);
            }
        };
        this.sendAjaxRequest = function(url, type, data) {
            $.ajax({
                url : url,
                type : type,
                data : data,
                dataType : "json",
                success : function(result) {
                    alert(result.message);
                    //重新加载table
                    $('#query_data').bootstrapTable('destroy');

                    var ReTable = new TableInit();
                    ReTable.Init();

                },
                error : function(result) {
                    alert("出错了,请检查导入的数据!");
                },
                cache : false,
                contentType : false,
                processData : false
            });
        };
    };

    //导出
    $('#dc').bind('click', function () {
       // var drawingNo = $("#Drawing_No").val();
       // var weldNo = $("#Weld_No").val();
        $.ajax({
            cache: true,
            type: "POST",
            data: "",
            url:encodeURI(g_BasePath+"exportlist.html"),
            async: false,
            error: function (request) {
                alert("导出失败！");
            },
            success: function (data) {

                //截掉下载地址里的引号
                var url=data.substring(1,data.length-1);
                /*  if (/(?:\"|\')/.test(data)) {
                 data = data.replaceAll("\"", "");
                 }*/
                window.open(g_BasePath + url);
                alert("导出成功");
            }
        });
    });
</script>
<body>
</body>
